//
//  DepoistInfoItem2Cell.swift
//  d11
//
//  Created by peale on 2018/10/21.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
typealias RemakChangeBlock = (_ remak: String) -> Void
class DepoistInfoItem2Cell: UITableViewCell {

    var bgImgView : UIImageView?
    var iconImgView : UIImageView?
    var titleLabel : UILabel?
    var textField : UITextField?
    var remakChangeBlock: RemakChangeBlock?
    func callChangeBlock(_ block: @escaping RemakChangeBlock) {
        
        remakChangeBlock = block
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        // self.contentView!.backgroundColor  = UIColor.clear
        self.bgImgView = UIImageView.init()
        self.bgImgView?.isUserInteractionEnabled = true
        self.bgImgView?.image = imageNamed("icon_my_cell_item")?.resizableImage(withCapInsets: UIEdgeInsets(top: 5, left: 30, bottom: 5, right: 30),resizingMode: .stretch) //左右15像素的部分不变，中间部分来拉伸
        self.contentView.addSubview(bgImgView!);
        self.bgImgView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview()
            make.height.equalTo(60)
            make.centerX.equalTo(self.contentView)
        };
        
        self.iconImgView = UIImageView.init()
        self.iconImgView?.image = imageNamed("icon_depoist_input_info_remark")
        self.bgImgView?.addSubview(self.iconImgView!)
        self.iconImgView?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(12)
            make.width.equalTo(20)
            make.height.equalTo(20)
            make.centerY.equalTo(self.bgImgView!)
        }
        self.titleLabel = UILabel.init()
        self.titleLabel?.text = "存款备注"
        self.titleLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        self.titleLabel?.textAlignment = NSTextAlignment.left
        self.bgImgView?.addSubview(self.titleLabel!)
        
        self.titleLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.iconImgView?.snp.right)!).offset(12)
            make.width.equalTo(70)
            make.height.equalTo(51)
            make.centerY.equalToSuperview()
        }
        
        self.textField = UITextField.init()
        self.textField?.textColor =  HexRGBAlpha(0x8E8F90, 1)
        self.textField?.font = UIFont.systemFont(ofSize: 12)
        self.textField?.textAlignment = NSTextAlignment.left
        self.textField?.placeholder = "例如工商银行+您的卡号后五位XXXXX"
        self.bgImgView?.addSubview(self.textField!)
        self.textField?.addTarget(self, action: #selector(self.actionToChanged(_:)), for: UIControl.Event.editingChanged)
        self.textField?.snp.makeConstraints{(make) in
            make.left.equalTo((self.titleLabel?.snp.right)!).offset(12)
            make.right.equalToSuperview().offset(-15)
            make.centerY.equalToSuperview()
            make.height.equalTo(51)
        }
        
    }
    
    func setData(inputText:String?,row:Int)->Void{
        self.textField?.text = inputText
    }
    
    @objc func actionToChanged(_ sender: UITextField) -> Void {
        if remakChangeBlock != nil {
            remakChangeBlock!(sender.text!)
        }
    }

}
